package com.jeomo.mem.provider.web;

import com.jeomo.common.core.result.CommonResult;
import com.jeomo.common.core.util.BeanCopyUtil;
import com.jeomo.mem.provider.request.PointsValidityReq;
import com.jeomo.mem.provider.vo.PointsValidityVo;
import com.jeomo.mem.starter.sysoption.PointsValiditySysOption;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 积分有效期
 */
@RestController
@RequestMapping("points")
public class PointsValidityController {

    @Resource
    private PointsValiditySysOption pointsValiditySysOption;

    @PostMapping("validity")
    public CommonResult saveOption(@RequestBody PointsValidityReq pointsValidityReq){

        BeanCopyUtil.copyProperties(pointsValidityReq,pointsValiditySysOption);
        boolean save = pointsValiditySysOption.save();
        return save?CommonResult.success("保存成功"):CommonResult.failure("保存失败");
    }

    @GetMapping("validity")
    public CommonResult<PointsValidityVo> getOption(){

        pointsValiditySysOption.load();
        PointsValidityVo pointsValidityVo = BeanCopyUtil.copyProperties(pointsValiditySysOption, PointsValidityVo.class);
        return CommonResult.success(pointsValidityVo);
    }

}
